mod util;
use clap::{Arg, ArgAction, Command};
use common::util::resolve_path;
use std::path::Path;

use util::sync;
const COMMAND_NAME: &str = "module_dev_sync";

const SOURCE: &str = "source";
const TARGET: &str = "target";
fn main() -> Result<(), Box<dyn std::error::Error>> {
    let matches = Command::new(COMMAND_NAME)
        .version("1.0")
        .author("caozongying<zongying_cao@163.com>")
        .about("caozongying_cao<zongying_cao@163.com> is the author")
        .arg(
            Arg::new(SOURCE)
                .short('s')
                .long(SOURCE)
                .value_name("SOURCE_PATH")
                .help("同步的源路径")
                .action(ArgAction::Set),
        )
        .arg(
            Arg::new(TARGET)
                .short('t')
                .long(TARGET)
                .value_name("TARGET_PATH")
                .help("同步的目标路径")
                .action(ArgAction::Set),
        )
        .get_matches();

    let source_path = matches
        .get_one::<String>(SOURCE)
        .unwrap_or_else(|| panic!("参数{}未提供", SOURCE));
    let target_path = matches
        .get_one::<String>(TARGET)
        .unwrap_or_else(|| panic!("参数{}未提供", TARGET));

    sync(
        &resolve_path(Path::new(source_path))?,
        &resolve_path(Path::new(target_path))?,
    )?;

    Ok(())
}
